package com.divinglogger.dao.impl;

import java.util.List;

import javax.persistence.EntityManager;

import com.divinglogger.dao.GreetingDao;
import com.divinglogger.domain.Greeting;
import com.divinglogger.domain.factory.EMF;

public class GreetingDaoImpl implements GreetingDao {

	@Override
	public void insertGreeting(Greeting greeting) {
		EntityManager em = EMF.getInstance().createEntityManager();
		try {
			em.persist(greeting);
		}
		finally {
			em.close();
		}		
	}

	@Override
	public List<Greeting> selectAllGreeting() {
		EntityManager em = EMF.getInstance().createEntityManager();
		String query = "select from Greeting";
		@SuppressWarnings("unchecked")
		List<Greeting> greetings = (List<Greeting>)em.createQuery(query).getResultList();
		return greetings;
	}

}
